<template>
  <div class="form-setting-panel">
    <!-- start 标题 -->
    <form-title-setting
      :field="field"
      :mode="mode"
      :setting="setting"
      @input="updateForDom"
    ></form-title-setting>
    <!-- end 标题 -->

    <!-- start 描述信息 -->
    <form-describe-setting
      :field="field"
      :mode="mode"
      @input="updateForDom"
    ></form-describe-setting>
    <!-- end 描述信息 -->

    <!-- start 校验 -->
    <div class="form-setting-group form-setting-item">
      <h4 class="form-item-title">{{$t('common.base.check')}}</h4>
      <div class="form-item-box">
        <!-- 必填 -->
        <form-required-setting :field="field" @input="update" v-if="!isRegisterFieldFlag"></form-required-setting>
        <!-- 不允许重复值 -->
        <form-repeat-setting v-if="!isServiceProviderFlag" :field="field" @input="update"></form-repeat-setting>
        <!-- 限制字数 -->
        <form-limit-word-setting :field="field" @input="update"></form-limit-word-setting>
      </div>
    </div>
    <!-- end 校验 -->

    <!-- start 默认值 -->
    <form-default-value-setting
      v-bind="$props"
      :fields="fields"
      :field="field"
      show-data-source
      @input="update"
    ></form-default-value-setting>
    <!-- end 默认值 -->

    <!-- start 字段权限 -->
    <div class="form-setting-group form-setting-item" v-if="!isOnlyEngineerFlag">
      <h4 class="form-item-title">{{$t('common.base.fieldPermissions')}}</h4>
      <div class="form-item-box">
        <!-- 移动端列表展示 -->
        <mobile-show-setting v-if="(isTaskMode || isOnlyEventMode || isOnlyProductMode) && !isServiceProviderFlag" :is-event-mode="isEventMode" :field="field" :fields="fields" @input="update"></mobile-show-setting>
        <!-- 可见性 -->
        <form-visible-setting :field="field" @input="update" v-if="!isServiceProviderFlag"></form-visible-setting>
        <!-- 支持高级搜索 -->
        <form-search-setting :field="field" @input="update" v-if="!isTaskCardForm&&mode!='product_register'"></form-search-setting>
        <!-- 是否对客户可见 -->
        <form-visible-customer-setting :field="field" @input="update" v-if="isShowVisibleCustomer"></form-visible-customer-setting>
      </div>
    </div>
    <!-- end 字段权限 -->

    <!-- start 其他设置 -->
    <div class="form-setting-group form-setting-item">
      <h4 class="form-item-title">{{$t('common.base.otherSet')}}</h4>
      <div class="form-item-box">
        <!-- 设为公用字段 -->
        <form-public-setting :field="field" @input="update" v-if="allowPublicSet"></form-public-setting>

        <el-checkbox :value="field.setting.isScanCode" @input="update($event, 'isScanCode', true)" :true-label="1" :false-label="0">
          {{$t('common.form.preview.text.des1')}}
          <el-tooltip :content="$t('common.form.preview.text.des2')" placement="top">
            <i class="iconfont icon-question"></i>
          </el-tooltip>
        </el-checkbox>

      </div>
    </div>
    <!-- end 其他设置 -->
  </div>
</template>

<script>
/* mixin */
import SettingMixin from '@src/component/form/mixin/setting';
/* props */
import { settingProps } from '@src/component/form/components/props';

export default {
  name: 'form-text-setting',
  mixins: [SettingMixin],
  props: settingProps,
  computed: {
    isRegisterFieldFlag() {
      return this.mode == 'product_register' && this.field.registerFieldFlag
    }
  },
  methods: {
    updateForDom(event){
      let el = event.target;
      let prop = el.dataset.prop;
      let value = el.value;
      this.update(value, prop);
    },
    update(value, prop, isSetting = false) {
      this.$emit('input', {value, prop, isSetting});
    }
  }
}
</script>
